package cn.hz.pi.api;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;


import cn.hz.pi.api.inteface.PiApi01;
import cn.hz.pi.api.inteface.PiApi02;
import cn.hz.pi.api.inteface.PiApi03;
import cn.hz.pi.api.inteface.PiApi04;
import cn.hz.pi.api.inteface.PiApi05;
import cn.hz.pi.api.inteface.PiApi06;
import cn.hz.pi.api.inteface.PiApi07;
import cn.hz.pi.api.inteface.PiApi64;
import cn.hz.pi.api.inteface.PiApiMethod;
import cn.hz.pi.api.util.DataManager;


/**
 * PI·API接口设定工具类
 * 
 * @author huazhuo
 *
 */
@Component
public class PiApiSetUtil {


  
	@Value("${piurl}")
	public   String piurl ="192.168.0.107"  ;

	/**
	 * 根据服务器标识，获取对应的API文件
	 * 
	 * @param server
	 *            服务器标识
	 * @return
	 */
	public static PiApiMethod getApi(DataManager server) {
		
		if(server == null){
			return PiApi64.INSTANCE;//默认的
		}
		
		switch (server.getNum()) {
		case 0:
			return PiApi64.INSTANCE;//默认的
		case 1:
			return PiApi01.INSTANCE;
		case 2:
			return PiApi02.INSTANCE;
		case 3:
			return PiApi03.INSTANCE;
		case 4:
			return PiApi04.INSTANCE;
		case 5:
			return PiApi05.INSTANCE;
		case 6:
			return PiApi06.INSTANCE;
		case 7:
			return PiApi07.INSTANCE;
		default:
			return PiApi64.INSTANCE;//默认的
		}
		
	}


	/**
	 * 根据服务器标识，获取对应的服务器IP地址
	 * 
	 * @param server
	 *            服务器标识
	 * @return
	 */
	public static String getServer(DataManager server) {
		if (null == server || null == server.getPiService()) {
			 
			return new PiApiSetUtil().getPiurl();
		}
		return server.getPiService();
	}


	public String getPiurl() {
		String piurl = AddressUtil.getProperty("hostname");
		return piurl;
	}


	public void setPiurl(String piurl) {
		this.piurl = piurl;
	}


	
	

}
